<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-12-16
 * Time: 10:08
 */

namespace app\water\controller;


use app\common\helper\FormatHelper;
use app\common\service\VoiceService;
use think\Db;

/**
 * 获取语音接口
 */
class Voice extends Auth
{
    public $noNeedLogin = [];

    /**
     * 下单商品语音获取接口
     *
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        /*if ($this->request->isPost()) {

            $userInfo = $this->userInfo;
            $voice_url = [];
            $config = Db::name('qt_water_config')->where('store_id', $userInfo['store_id'])->find();
            $config['play_number'] = !empty($config['play_number']) ? $config['play_number'] : 2;//播放次数
            $order_item = Db::name('qt_product_order_item')
                ->alias('oi')
                ->field([
                    'oi.id',
                    'oi.goods_name',
                    'oi.goods_num',
                    'oi.goods_total_price',
                    'po.room_id',
                    'r.name as room_name',
                    'po.engineer_id',
                ])
                ->leftJoin('qt_product_order po', 'po.id=oi.order_id')
                ->leftJoin('qt_room r', 'po.room_id=r.id')
                ->where('oi.store_id', $userInfo['store_id'])
                ->where('oi.is_broadcast', 2)//未播报
                ->order('oi.create_time asc')
                ->select();

            //设置不接受房间，不播报
            $noreceive_room = explode(',', $config['noreceive_room']);

            //下单播报
            foreach ($order_item as $key => $val) {
                //更新为播报
                Db::name('qt_product_order_item')->where('id', $val['id'])->update(['is_broadcast' => 1]);

                if (!empty($noreceive_room) && in_array($val['room_id'], $noreceive_room)) {
                    continue;
                }

                $text = '房间  ' . $val['room_name'] . '    ' . $val['goods_name'] . '    数量   ' . $val['goods_num'];
                $result = VoiceService::createVoice($text,$config['play_speed'],$config['play_number']);
                if ($result['code'] == FormatHelper::SUCCESS) {
                    $voice_url[] = $result['data'];
                }
            }

            //商品退单播报
            $send_voice_msg = Db::name('qt_send_voice_msg')->where('type', 1)->column('content');
            if (!empty($send_voice_msg)) {
                foreach ($send_voice_msg as $key => $text) {
                    $result = VoiceService::createVoice($text,$config['play_speed'],$config['play_number']);
                    if ($result['code'] == FormatHelper::SUCCESS) {
                        $voice_url[] = $result['data'];
                    }
                }
                //Db::name('qt_send_voice_msg')->where('type', 1)->delete();//查一次清空一次
            }

            $this->result('查询成功', $voice_url, 200);
        }*/

        $this->result('请求失败', [], 204);
    }
}
